package com.jia.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jia.entity.ChatFriend;
import com.jia.entity.SysUser;
import com.jia.mapper.ChatFriendMapper;
import com.jia.mapper.SysUserMapper;
import com.jia.service.ChatFriendService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 杜佳佳
 * @since 2021-05-30
 */
@Service
public class ChatFriendServiceImpl extends ServiceImpl<ChatFriendMapper, ChatFriend> implements ChatFriendService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public List<ChatFriend> getFriendListByUserId(String userId) {
        QueryWrapper<ChatFriend> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        List<ChatFriend> chatFriends = baseMapper.selectList(wrapper);
        chatFriends.forEach(item -> {
            SysUser sysUser = sysUserMapper.selectById(item.getFriendId());
            item.setSysUser(sysUser);
        });
        return chatFriends;
    }
}
